package logic

import (
	"context"
	"gitee.com/A1001574000/feedback-rpc/feedback"
	"gitee.com/A1001574000/feedback-rpc/internal/svc"
	"gitee.com/A1001574000/feedback-rpc/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type FeedbackImgByIDLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFeedbackImgByIDLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FeedbackImgByIDLogic {
	return &FeedbackImgByIDLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FeedbackImgByIDLogic) FeedbackImgByID(in *feedback.FeedbackImgByIDRequest) (*feedback.FeedbackImgByIDResponse, error) {
	feedbackImg := new(model.FeedbackImg)
	imgs, err := feedbackImg.SelectById(in.UserID)
	if err != nil {
		return nil, err
	}

	imgInfoList := make([]*feedback.FeedbackImgInfo, 0)
	for _, img := range imgs {
		imgInfo := &feedback.FeedbackImgInfo{
			UserId: img.UserId,
			Img:    img.FeedbackImg,
		}
		imgInfoList = append(imgInfoList, imgInfo)
	}

	return &feedback.FeedbackImgByIDResponse{
		ImgInfo: imgInfoList,
	}, nil
}
